<?php

namespace App\Http\Controllers\Contract;

use App\Helpers\ContractApiTrait;
use App\Helpers\ResponseData;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Models\Contract\CarContract;
use Modules\Car\Entities\CarOrder;
use Illuminate\Support\Facades\Http;

class ContractFileController extends Controller
{
    use ResponseData, ContractApiTrait;

    //
    public function uploadComponentFile(Request $request){

        if(empty($request->upload_file)){
            return $this->failed('文件信息不能为空');
        }
        $uploadFile=is_array($request->upload_file)?$request->upload_file:json_decode($request->upload_file,true);
        if(empty($uploadFile)){
            return $this->failed('文件信息不能为空');
        }
        $data=[
            'businessType'=>'DOCUMENT',
            'uploadFile'=>$uploadFile,
            'agent'=>$this->getAgent(),
        ];
        if($request->org_openid && $request->operator_openid){
            $data['agent']=$this->getAgent($request->org_openid,$request->operator_openid);
        }
        $requestData=$this->getRequestData('UploadFiles',$data);
        $response=Http::post($this->getQizongApiUrl(),$requestData);
        $resData=$response->json();
        if(isset($resData['code']) && $resData['code']==0){
            return $this->success($resData);
        }
        $this->createContractErrorLog('上传文件失败',$resData,$request);
        return $this->failed($resData['msg']);
    }

}
